package com.shared.rule;




/**
 * Enumeration des opérateur possible du systeme de decision (lié au {@link TypeDataRule}) 
 * @author queyroi
 *
 */
public enum TypeOperator {
	
	NOMINAL_EQUAL("NominalOperatorEqual"),
	NOMINAL_NON_EQUAL("NominalOperatorNonEqual"),
	NUMERIC_EQUAL("NumericOperatorEqual"),
	NUMERIC_NON_EQUAL("NumericOperatorNonEqual"),
	NUMERIC_LESSER("NumericOperatorLesser"),
	NUMERIC_GREATER("NumericOperatorGreater"),
	BOOLEAN_EQUAL("BooleanOperatorEqual"),
	BOOLEAN_NON_EQUAL("BooleanOperatorNonEqual");
	
	private String label;
	
	private TypeOperator(String label){
		this.label=label;
	}
	
	public String toString() {
		return label;
	}
	
	public void setLabel(String label) {
		this.label = label;
	}
	
	public static TypeOperator getType(String l){
		for(TypeOperator type : TypeOperator.values()) if(type.toString().equals(l)) return type;
		return null;
	}
		
	public TypeDataRule getTypeData(){
		String l = toString().substring(0, toString().indexOf("Operator"));
		return TypeDataRule.getEnum(l);
	}
	
	public static TypeOperator getTypeOperator(String operator,TypeDataRule typeData){
		switch (typeData) {
		case NUMERIC:
			if(operator=="=") return TypeOperator.NUMERIC_EQUAL;
			if(operator=="<>") return TypeOperator.NUMERIC_NON_EQUAL;
			if(operator=="<") return TypeOperator.NUMERIC_LESSER;
			if(operator==">") return TypeOperator.NUMERIC_GREATER;
		case NOMINAL:
			if(operator=="=") return TypeOperator.NOMINAL_EQUAL;
			if(operator=="<>") return TypeOperator.NOMINAL_NON_EQUAL;
		case BOOLEAN:
			if(operator=="=") return TypeOperator.BOOLEAN_EQUAL;
			if(operator=="<>") return TypeOperator.BOOLEAN_NON_EQUAL;
		default:
			return null;
		}
		
	}
}

